const dataBase = require('../dataBase')


// 获取用户信息处理函数
function getUserInfo(req, res){
    const sccountNumber = req.body.sccountNumber
    const getUserInfoSql = 'select id, nickname, sex, birthday, university, college, enrollmentTime, userType, headImageSrc, phoneNumber, QQMail from personalinformation where phoneNumber = ? || QQMail = ?'
    dataBase.query(getUserInfoSql, [sccountNumber, sccountNumber], (err, results) => {
        if(err){
            return res.ErrorFun('未知错误！请稍后再试！')
        }
        
        res.send({
            status: 200,
            message: '获取成功！',
            userInfo: results[0]
        })
    })
}

// 完善用户信息处理函数
function improveUserInformation(req, res){
    const gimproveUserInformationSql = ''
}


// 更换用户头像处理函数
function updateHeadImg(req, res){
    const updateHeadImgSql = 'update personalinformation set headImageSrc = ? where id = ?'

    dataBase.query(updateHeadImgSql, [req.body.headImageSrc, req.body.id], (err, results) => {
        if(err){
            return res.ErrorFun('未知错误！请稍后再试！')
        }

        if(results.affectedRows !== 1){
           return res.ErrorFun('更换失败！')
        }

        res.send({
            status: 200,
            message: '更换成功！'
        })
    })
}

module.exports = {
    getUserInfo,
    improveUserInformation,
    updateHeadImg
}